package com.jinke.uang.ui.activity.personal;

import android.content.Intent;
import android.net.Uri;
import android.os.Vibrator;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.jinke.uang.R;
import com.jinke.uang.base.BaseNetActivity;
import com.jinke.uang.common.RouterMap;
import com.jinke.uang.common.NoDoubleClickListener;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 借款申请状态展示页的
 */
@Route(name = "状态展示页", path = RouterMap.STATUS_DISPLAY)
public class StatusDisplayActivity extends BaseNetActivity {

    public static String PAGE_TYPE_KEY = "page_type_key";

    @BindView(R.id.topBack)
    ImageView topBack;
    @BindView(R.id.topText)
    TextView topText;
    @BindView(R.id.tvGoHome)
    TextView tvGoHome;
    @BindView(R.id.tvSee)
    TextView tvSee;
    @BindView(R.id.tvHint)
    TextView tvHint;
    @BindView(R.id.linCall)
    LinearLayout linCall;


    //0:认证结果 1:借款结果 2:换卡结果
    private int pageType = 0;

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
    }

    @Override
    protected void onUIReady() {
        pageType = getIntent().getIntExtra(PAGE_TYPE_KEY, 0);
        topBack.setOnClickListener(viewclick);
        //获取头部信息
        topText.setText(R.string.result_title);
        //地址信息
        tvGoHome.setOnClickListener(viewclick);
        tvSee.setOnClickListener(viewclick);
        linCall.setOnClickListener(viewclick);
        if (0 == pageType) {
            tvHint.setText(R.string.result_borrow_hint);
        } else {
            tvHint.setText(R.string.result_hint);
        }

        if(1==pageType){ //震动
            Vibrator vibrator = (Vibrator) StatusDisplayActivity.this.getSystemService(VIBRATOR_SERVICE);
            vibrator.vibrate(1000);
        }
    }

    /**
     * 点击信息
     */
    private NoDoubleClickListener viewclick = new NoDoubleClickListener() {
        @Override
        public void onNoDoubleClick(View v) {
            super.onNoDoubleClick(v);
            switch (v.getId()) {
                case R.id.topBack:
                    finish();
                    break;
                case R.id.tvGoHome:
                    //首页
                    ARouter.getInstance().build(RouterMap.MAIN_ACTIVITY_PAGE).navigation();
                    finish();
                    break;
                case R.id.tvSee:
                    //订单
                    if (pageType == 0) {
                        ARouter.getInstance().build(RouterMap.BORROW_PAGE).navigation();
                    } else if (1 == pageType) {
                        //借款详情
                        ARouter.getInstance().build(RouterMap.MINE_BROWING).navigation();
                    } else {
                        ARouter.getInstance().build(RouterMap.MAIN_ACTIVITY_PAGE).navigation();
                    }
                    finish();
                    break;
                case R.id.linCall:
                    //联系客服
                    Intent intent = new Intent(Intent.ACTION_DIAL);
                    Uri data = Uri.parse("tel:" + getString(R.string.help_center_service_tel));
                    intent.setData(data);
                    startActivity(intent);
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    protected int getContentResId() {
        return R.layout.activity_status_display;
    }

    @Override
    public String getPageTitle() {
        return null;
    }

    @Override
    protected int getResId() {
        return 0;
    }

}
